


import os
import sys
import shutil
import glob

matlabpath = [r"D:\Program Files\MATLAB\R2010a\bin",r"C:\Program Files\MATLAB\R2010a\bin"]

print("add default matlab bin path to sys's paths \r\n" + str(matlabpath))

mfile = "test.m"
output = "test"
buildclibcmd = "mcc - B csharedlib:" + output + " " + mfile

os.sys.path.append(matlabpath)

""" mex -l lib.MatlabExtension.lib GetQuoteHistory.c"""


'''
def copylibfile():
    print("copy lib file to local directory\n")
    srcf = r"..\Debug\lib.MatlabExtension.lib"
    desf =r"lib.MatlabExtension.lib"
    try:
        shutil.copy(srcf,desf)
    except:
        print("file not found")
        pass


    srcf = r"..\Debug\lib.MatlabExtension.dll"
    desf =r"lib.MatlabExtension.dll"

    try:
        shutil.copy(srcf,desf)
    except:
        print("file not found")
        pass
'''


def delpreviousfiles():
    
    os.system("del *.mex y")



def compile(fname):
    print("--------------\n" + fname)


    cmd = "mex "     + fname  + " -L..\\Debug\\  -llib.MatlabExtension  -outdir ..\\Debug\\"
    os.system(cmd)
    print("\n\n\n\n")





if __name__ == '__main__':
   # copylibfile()
    delpreviousfiles()
    items = glob.glob("*.cpp")
    for item in items:
        try:
            compile(item)
	except:
	    pass
    os.system("pause")






